*create tract to border xxwalk

use suppdata/sf12010tractdistance100miles, replace 

gen state1=substr(county1,1,2) 
gen state2=substr(county2,1,2) 


keep if state1!=state2 // only across borders

rename mi_to_tract distance

gen region_name=county1+tract1

destring region_name, replace

// only closest border

bysort region_name: egen rank_dist=rank(distance)
keep if rank_dist==1

*egen border=group(state1 state2) // no this is wrong

egen  i = group(state1)
egen  j = group(state2)
rowsort i j, gen(si sj)
egen border = group(si sj)

keep region_name border distance


save  ../Data/CleanedData/TractDistancesXXwalk, replace
